package com.weiaibenpao.demo.chislim.presenter;

import com.orhanobut.logger.Logger;
import com.weiaibenpao.demo.chislim.base.BasePresenter;
import com.weiaibenpao.demo.chislim.bean.EmptyBean;
import com.weiaibenpao.demo.chislim.bean.MessageListBean;
import com.weiaibenpao.demo.chislim.retrofit.RetrofitUtils;
import com.weiaibenpao.demo.chislim.retrofit.rx.NetWorkTransformer;
import com.weiaibenpao.demo.chislim.retrofit.rx.SimpleObserver;
import com.weiaibenpao.demo.chislim.utils.Constant;
import com.weiaibenpao.demo.chislim.view.MessageListView;

/**
 * Created by Administrator on 2018/1/5.
 */

public class MessageListPresenter extends BasePresenter<MessageListView> {

    public void getMessageList(int userId,int page){
        Logger.e("getMessageList----->");
        RetrofitUtils
                .getAPIService()
                .getMessageList(userId,page, Constant.DEFAULT_PAGE_SIZE)
                .compose(new NetWorkTransformer<MessageListBean>())
                .subscribe(new SimpleObserver<MessageListBean>(mCompositeDisposable) {
                    @Override
                    public void call(MessageListBean bean) {
                        getView().onGetMessageListSuccess(bean);
                    }

                    @Override
                    public void showErrorMsg(String message) {
                        if(getView() != null)
                            getView().onGetMessageListFailed(message);
                    }
                });
    }

    public void clearAllMessage(int userId){
        Logger.e("clearAllMessage----->"+userId);
        RetrofitUtils
                .getAPIService()
                .clearAllMessage(userId)
                .compose(new NetWorkTransformer<EmptyBean>())
                .subscribe(new SimpleObserver<EmptyBean>(mCompositeDisposable) {
                    @Override
                    public void call(EmptyBean bean) {
                        getView().onClearMessageSuccess();
                    }

                    @Override
                    public void showErrorMsg(String message) {
                        if(getView() != null)
                            getView().onClearMessageFailed(message);
                    }
                });
    }

}
